<template>
  <transition name="slide">
    <music-list :title="title" :bg-img="bgImg" :songs="songs"></music-list>
  </transition>
</template>

<script>
import MusicList from '../music-list/music-list'
import {mapGetters} from 'vuex'
import {getDescSong} from '@/api/recommend'
import {ERR_OK} from '@/api/config'
import {creatSong, processSongsUrl, isValidMusic} from '@/common/js/song'
export default {
  components: {
    MusicList
  },
  props: {},
  data() {
    return {
      songs: []
    }
  },
  watch: {},
  computed: {
    ...mapGetters(['desc']),
    title() {
      return this.desc.dissname
    },
    bgImg() {
      return this.desc.imgurl
    }
  },
  created() {
    this._getDescSong()
  },
  mounted() {},
  methods: {
    _getDescSong() {
      if (!this.desc.dissid) {
        this.$router.push({
          path: '/recommend'
        })
        return
      }
      getDescSong(this.desc.dissid).then((res) => {
        if (res.code === ERR_OK) {
          let songList = res.cdlist[0].songlist
          console.log(songList)
          processSongsUrl(this._normalLizeSongs(songList)).then((songs) => {
            this.songs = songs
          })
        }
      })
    },
    _normalLizeSongs(list) {
      let ret = []
      list.forEach(element => {
        if (isValidMusic(element)) {
          ret.push(creatSong(element))
        }
      })
      return ret
    }
  }
}
</script>
<style lang="stylus" scoped>
.slide-enter-active,.slide-leave-active{
  transition: all 0.3s
}
.slide-enter,.slide-leave-to{
  transform: translate3d(100%, 0, 0)
}
</style>